// Calendar Chooser
// @author : Sebastian Mosser

var monthsName = new Array();
monthsName[1] = "Janvier";
monthsName[2] = "Février";
monthsName[3] = "Mars";
monthsName[4] = "Avril";
monthsName[5] = "Mai";
monthsName[6] = "Juin";
monthsName[7] = "Juillet";
monthsName[8] = "Aout";
monthsName[9] = "Septembre";
monthsName[10] = "Octobre";
monthsName[11] = "Novembre";
monthsName[12] = "Décembre";

function displayBalloonCal(formElemId) {
	var htmlDocument = "<html>";
	htmlDocument += "<head> <title> Choix d'une date </title> ";
	htmlDocument += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
	htmlDocument += "<script type=\"text/javascript\">\n";
	htmlDocument += balloonPrintFunctions(formElemId);
	htmlDocument += "</script></head><body>";
	
	var days = "";
	for (i = 1; i < 32; i += 1) {
		days += "<option value='"+i+"'> " + i + " </option>";
	}
	days = "<select id=\"day\"> "+ days + "</select>";

	var months = "";
	for (i = 1; i < 13; i += 1) {
		months += "<option value='"+i+"'>" + monthsName[i] + " </option>";
	}
	months = "<select id=\"month\">" + months + "</select>";
	
	var years = "";
	var currentYear = new Date();
	currentYear = currentYear.getFullYear();
	for (i = currentYear ; i > 1900; i -= 1) {
		years += "<option value='"+i+"'> "+i+"</option>";
	}
	years = "<select id='year'>" + years + "</select>";
	
	htmlDocument += "<p> Selectionnez la date a entrer dans le système </p>";
	htmlDocument += "<br/><center>";
	htmlDocument += days + "&nbsp;";
	htmlDocument += months + "&nbsp;";
	htmlDocument += years + "&nbsp;";
	htmlDocument += "<br /> <br />"; 
	htmlDocument += "<input type=\"button\" onclick=\"balloonSetDate()\" value=\"Valider\"/>";
	htmlDocument += "</center></body> </html>";
	
	calWin = window.open("","","directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=500,height=200");
	calWin.document.open();
  calWin.document.write(htmlDocument);
  calWin.document.close();

}

function balloonPrintFunctions(formElem) {
  var func = "";
  func += "function balloonSetDate() { \n";
  func += "  var year = document.getElementById(\"year\").value;\n";
  func += "  var month = document.getElementById(\"month\").value;\n";
  func += "  var day = document.getElementById(\"day\").value;\n";
  func += "  if (month.length == 1)\n";
  func += "    month = \"0\"+month;\n";
  func += "  if (day.length == 1)\n";
  func += "    day = \"0\"+day;\n";
  func += "  var result = year + \"-\"+month+\"-\"+day;\n";
  func += "  window.opener.document.getElementById(\""+formElem+"\").value = result;\n";
  func += "  self.close();\n";
  func += "}\n";
  return func;

}

